package cn.gzmli.dtt.common.controll;


import cn.gzmli.dtt.common.utils.Constant;
import cn.gzmli.dtt.common.entity.Faq;
import cn.gzmli.dtt.common.entity.PageInfo;
import cn.gzmli.dtt.common.entity.Result;
import cn.gzmli.dtt.common.service.FaqService;
import cn.gzmli.dtt.common.utils.BaseController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/faq")
public class FaqController implements BaseController<Faq> {


    @Autowired
    private FaqService faqService;

    @Override
    public Result lists(HttpServletRequest request, PageInfo pageInfo) throws Exception {
        return null;
    }

    @Override
    @RequestMapping("/save")
    @ResponseBody
    public Result save(Faq faq) throws Exception {
        this.faqService.addFaq(faq);
        return new Result(Constant.SUCCESS, "添加成功");
    }

    @RequestMapping("/addCount")
    @ResponseBody
    public Result updateClickCount(Faq faq) throws Exception {
        if(faq.getId()!=null&&faq.getId()!=0){
            this.faqService.updateAddCount(faq.getId());
        }
        return new Result(Constant.SUCCESS, "增加计数成功");

    }

    @Override
    @RequestMapping("/update")
    @ResponseBody
    public Result update(Faq faq) throws Exception {
        this.faqService.updateFaq(faq);
        return new Result(Constant.SUCCESS, "修改成功");
    }

    @Override
    @RequestMapping("/delete")
    @ResponseBody
    public Result delete(Faq faq) throws Exception {
        this.faqService.deleteFaq(faq);
        return new Result(Constant.SUCCESS, "删除成功");
    }

    @Override
    @RequestMapping("/get")
    @ResponseBody
    public Result get(Integer id) throws Exception {
        return new Result(Constant.SUCCESS,"获取问题成功",this.faqService.get(id));
    }

    @Override
    public Result list() throws Exception {
        return null;
    }

    @RequestMapping("/list")
    @ResponseBody
    public Result list(String mQuestion,PageInfo pageInfo,int mpage) throws Exception {
        return new Result(Constant.SUCCESS,"获取FAQ列表成功",this.faqService.getAll2(mQuestion,pageInfo,mpage),pageInfo);
    }


    /**
     * ?page=1&limit=30
     * @return
     * @throws Exception
     */
    @RequestMapping("/layUiList")
    @ResponseBody
    public Map<String, Object> layuiList(Faq faq, int page, int limit) throws Exception {
        return this.faqService.getLayuiList(page,limit);
    }

    @Override
    public Result listByCondition(HttpServletRequest request, PageInfo pageInfo) throws Exception {
        return null;
    }

    @Override
    public Result getByCondition(HttpServletRequest request) throws Exception {
        return null;
    }
}
